﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace RestaurateurConsole
{
    public partial class WillNotRun : Form
    {
        string err;
        bool doNotContinue = false;
        Form mainForm;

        private WillNotRun() { }

        public WillNotRun(String err, Form mainForm)
        {
            this.err = err;
            this.mainForm = mainForm;
            InitializeComponent();
        }

        public WillNotRun(string err, bool DoNotContinue)
        {
            this.err = err;
            doNotContinue = DoNotContinue;
            InitializeComponent();
        }

        string key;
        private void WillNotRun_Load(object sender, EventArgs e)
        {
            this.Hide();
            MessageBox.Show(err);
            if (doNotContinue)
            {
                this.Close();
                return;
            }
            else
            {
                this.Show();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (IsValidKey(sender == null ? key : textBox1.Text))
            {
                ConfigHandler.Configuration.RegistrationKey = sender == null ? key : textBox1.Text;
                ConfigHandler.Configuration.Save();
                (mainForm as RestaurateurGUI.MainForm).toolStripMenuItem3_Click(null, null);
                RestaurateurGUI.MainForm.CreatorForm = this;
                (mainForm as RestaurateurGUI.MainForm).Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("Wrong key entered; please enter the correct key or contact Shomu.");
                textBox1.SelectAll();
            }
        }

        public static bool IsValidKey(string key)
        {
            if (key.Length != 16)
                return false;
            if (key != key.ToUpper())
                return false;
            switch (key)
            {
                case "FE22GA11RO44BY88":
                    return true;
                case "BA78LU23RG12HA8T":
                    return true;
                default:
                    return false;
            }
        }
    }
}
